package thirdassigment;

import java.io.File;

public class Delete implements ICommandExecutor{
	private static ICommandExecutor instance;
public void execute(String enterstr){
	
	String[] StrArray = enterstr.split(" ");
	String path = StrArray[1];
	
	File d = new File(path);
	if(!d.exists()) 
		System.out.println("This file does not exist");
	else{ 
		delete(d);
		if(!d.exists()){
			System.out.println(d.getName() + "Deleted");
		}else {
				  System.out.println("Delete failed");
		}
	}
	/*if(!d.delete())
		  System.out.println("Delete failed");
	*/
} 

private void delete(File del){
	
	if(del.isDirectory())
	{
		for (File f : del.listFiles())
		{
			f.delete();
		}
	del.delete();	
}else del.delete();

	
}
private Delete(){
}
public static ICommandExecutor getInstance() {
    if(instance==null){
            instance=new Delete();       
            }
    return instance;
}
}